<?php
namespace BP\En;
require_once("java/math/BigDecimal.php");
require_once("java/util/ArrayList.php");
require_once("java/util/List.php");
require_once("BP/DA/Cash.php");
require_once("BP/DA/CashEntity.php");
require_once("BP/DA/DataColumn.php");
require_once("BP/DA/DataRow.php");
require_once("BP/DA/DataSet.php");
require_once("BP/DA/DataTable.php");
require_once("BP/DA/DataType.php");
require_once("BP/DA/Paras.php");
abstract class Entities extends ArrayList {
	protected static $serialVersionUID;	// long
	public static function __staticinit() { // static class members
		self::$serialVersionUID = 1;
	}
	public function RetrieveAllFromDBSource () 
	{
		$qo = QueryObject::constructor__Entities($this);
		return $qo->DoQuery();
	}
	public function RetrieveAllFromDBSource_String ($orderByAttr) // [String orderByAttr]
	{
		$qo = QueryObject::constructor__Entities($this);
			/* match: String */
		$qo->addOrderBy_String($orderByAttr);
		return $qo->DoQuery();
	}
	public static function convertEntities ($obj) // [Object obj]
	{
		return $obj;
	}
	public function Filter_String_String ($key, $val) // [String key, String val]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($en->GetValStringByKey($key)->equals($val))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function Filter_String_String_String_String ($key1, $val1, $key2, $val2) // [String key1, String val1, String key2, String val2]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if (($en->GetValStringByKey($key1)->equals($val1) && $en->GetValStringByKey($key2)->equals($val2)))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function Filter_String_String_String_String_String_String ($key1, $val1, $key2, $val2, $key3, $val3) // [String key1, String val1, String key2, String val2, String key3, String val3]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if ((($en->GetValStringByKey($key1)->equals($val1) && $en->GetValStringByKey($key2)->equals($val2)) && $en->GetValStringByKey($key3)->equals($val3)))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function RetrieveByAttr ($attr, $val) // [String attr, Object val]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($attr, $val);
		return $qo->DoQuery();
	}
	public function RetrieveLikeAttr ($attr, $val) // [String attr, String val]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_String_String($attr, " like ", $val);
		return $qo->DoQuery();
	}
	public function getIsGradeEntities () 
	{
		try 
		{
			$attr = NULL;
			$attr = $this->getNewEntity()->getEnMap()->GetAttrByKey("Grade");
			$attr = $this->getNewEntity()->getEnMap()->GetAttrByKey("IsDtl");
			return  TRUE ;
		}
		catch (\Exception $e)
		{
			return  FALSE ;
		}
	}
	public function ExpDataToXml ($file) // [String file]
	{
		$dt = $this->ToDataTableField();
		$ds = new DataSet();
		$ds->Tables->add($dt);
		$ds->WriteXml($file);
		return $dt->Rows->size();
	}
	public function InitCollectionByTable_DataTable_String ($dt, $fieldName) // [DataTable dt, String fieldName]
	{
		$en = $this->getNewEntity();
		$pk = $en->getPK();
		foreach ($dt->Rows as $dr) 		{
			$en1 = $this->getNewEntity();
			$en1->SetValByKey_String_F($pk, $dr->getValue($fieldName));
			$en1->Retrieve();
			/* match: Entity */
			$this->AddEntity_Entity($en1);
		}
	}
	public function InitCollectionByTable_DataTable ($dt) // [DataTable dt]
	{
		try 
		{
			foreach ($dt->Rows as $dr) 			{
				$en = $this->getNewEntity();
				foreach ($en->getEnMap()->getAttrs() as $attr) 				{
					if (($attr->getMyFieldType() == FieldType::$RefText))
					{
						try 
						{
							$en->getRow()->SetValByKey($attr->getKey(), $dr->getValue($attr->getKey()));
						}
						catch (\Exception $e)
						{ /* empty */ }
					}
					else
					{
						$en->getRow()->SetValByKey($attr->getKey(), $dr->getValue($attr->getKey()));
					}
				}
			/* match: Entity */
				$this->AddEntity_Entity($en);
			}
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException(("@此表不能向集合转换详细的错误:" . $ex->getMessage()));
		}
	}
	public function equals ($ens) // [Entities ens]
	{
		if (($ens->size() != $this->size()))
		{
			return  FALSE ;
		}
		foreach (Entities::convertEntities($this) as $en) 		{
			$isExits =  FALSE ;
			foreach (Entities::convertEntities($ens) as $en1) 			{
				if ($en->getPKVal()->equals($en1->getPKVal()))
				{
					$isExits =  TRUE ;
					break;
				}
			}
			if (!$isExits)
			{
				return  FALSE ;
			}
		}
		return  TRUE ;
	}
	public static function constructor__ () 
	{
		$me = new self();
		return $me;
	}
	public function IsExits ($key, $val) // [String key, Object val]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($val->equals($en->GetValStringByKey($key)))
			{
				return  TRUE ;
			}
		}
		return  FALSE ;
	}
	abstract function getNewEntity (); 
	public function getItem ($index) // [int index]
	{
		return (( (($this->get($index) instanceof Entity)) ? $this->get($index) : NULL ));
	}
	public function AddEntity_Entity ($entity) // [Entity entity]
	{
		$this->add($entity);
	}
	public function AddEntity_Entity_I ($entity, $idx) // [Entity entity, int idx]
	{
		$this->add($idx, $entity);
		return $idx;
	}
	public function AddEntities_Entities ($ens) // [Entities ens]
	{
		foreach (Entities::convertEntities($ens) as $en) 		{
			/* match: Entity */
			$this->AddEntity_Entity($en);
		}
	}
	public function AddEntities_String ($pks) // [String pks]
	{
		$this->clear();
		if ((($pks . NULL) . $pks->equals("")))
		{
			return ;
		}
		$strs = $pks->split("[@]", -1);
		foreach ($strs as $str) 		{
			if ((($str == NULL) || $str->equals("")))
			{
				continue;
			}
			$en = $this->getNewEntity();
			$en->setPKVal($str);
			if (($en->RetrieveFromDBSources() == 0))
			{
				continue;
			}
			/* match: Entity */
			$this->AddEntity_Entity($en);
		}
	}
	public function Contains_Entity ($en) // [Entity en]
	{
		return $this->Contains_Object($en->getPKVal());
	}
	public function Contains_Entities ($ens) // [Entities ens]
	{
		return $this->Contains_Entities_String($ens, $ens->getNewEntity()->getPK());
	}
	public function Contains_Entities_String ($ens, $key) // [Entities ens, String key]
	{
		if (($ens->size() == 0))
		{
			return  FALSE ;
		}
		foreach (Entities::convertEntities($ens) as $en) 		{
			if (!$this->Contains_String_Object($key, $en->GetValByKey($key)))
			{
				return  FALSE ;
			}
		}
		return  TRUE ;
	}
	public function Contains_Entities_String_String ($ens, $key1, $key2) // [Entities ens, String key1, String key2]
	{
		if (($ens->size() == 0))
		{
			return  FALSE ;
		}
		foreach (Entities::convertEntities($ens) as $en) 		{
			/* match: String_Object_String_Object */
			if (!$this->Contains_String_Object_String_Object($key1, $en->GetValByKey($key1), $key2, $en->GetValByKey($key2)))
			{
				return  FALSE ;
			}
		}
		return  TRUE ;
	}
	public function Contains_Object ($pkVal) // [Object pkVal]
	{
		$pk = $this->getNewEntity()->getPK();
		return $this->Contains_String_Object($pk, $pkVal);
	}
	public function Contains_String_Object ($attr, $pkVal) // [String attr, Object pkVal]
	{
		foreach (Entities::convertEntities($this) as $myen) 		{
			if ($myen->GetValByKey($attr)->equals($pkVal))
			{
				return  TRUE ;
			}
		}
		return  FALSE ;
	}
	public function Contains_String_Object_String_Object ($attr1, $pkVal1, $attr2, $pkVal2) // [String attr1, Object pkVal1, String attr2, Object pkVal2]
	{
		foreach (Entities::convertEntities($this) as $myen) 		{
			if (($myen->GetValByKey($attr1)->equals($pkVal1) && $myen->GetValByKey($attr2)->equals($pkVal2)))
			{
				return  TRUE ;
			}
		}
		return  FALSE ;
	}
	public function Contains_String_Object_String_Object_String_Object ($attr1, $pkVal1, $attr2, $pkVal2, $attr3, $pkVal3) // [String attr1, Object pkVal1, String attr2, Object pkVal2, String attr3, Object pkVal3]
	{
		foreach (Entities::convertEntities($this) as $myen) 		{
			if ((($myen->GetValByKey($attr1)->equals($pkVal1) && $myen->GetValByKey($attr2)->equals($pkVal2)) && $myen->GetValByKey($attr3)->equals($pkVal3)))
			{
				return  TRUE ;
			}
		}
		return  FALSE ;
	}
	public function GainIntersection ($ens) // [Entities ens]
	{
		$myens = $this->CreateInstance();
		$pk = $this->getNewEntity()->getPK();
		foreach (Entities::convertEntities($this) as $en) 		{
			foreach (Entities::convertEntities($ens) as $hisen) 			{
				if ($en->GetValByKey($pk)->equals($hisen->GetValByKey($pk)))
				{
			/* match: Entity */
					$myens->AddEntity_Entity($en);
				}
			}
		}
		return $myens;
	}
	public function CreateInstance () 
	{
		return ClassFactory::GetEns($this);
	}
	public function GetEntityByKey_Object ($val) // [Object val]
	{
		$pk = $this->getNewEntity()->getPK();
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($val->equals($en->GetValStrByKey($pk)))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function GetEntityByKey_String_Object ($attr, $val) // [String attr, Object val]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			$v = $en->GetValByKey($attr);
			if ((($v != NULL) && $v->equals($val)))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function GetEntityByKey_String_I ($attr, $val) // [String attr, int val]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if (($en->GetValIntByKey($attr) == $val))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function GetEntityByKey_String_Object_String_Object ($attr1, $val1, $attr2, $val2) // [String attr1, Object val1, String attr2, Object val2]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if (($val1->equalsIgnoreCase($en->GetValStrByKey($attr1)) && $val2->equalsIgnoreCase($en->GetValStrByKey($attr2))))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function GetEntityByKey_String_Object_String_Object_String_Object ($attr1, $val1, $attr2, $val2, $attr3, $val3) // [String attr1, Object val1, String attr2, Object val2, String attr3, Object val3]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if ((($en->GetValByKey($attr1)->equals($val1) && $en->GetValByKey($attr2)->equals($val2)) && $en->GetValByKey($attr3)->equals($val3)))
			{
				return $en;
			}
		}
		return NULL;
	}
	public function GetSumDecimalByKey_String ($key) // [String key]
	{
		$sum = new BigDecimal(0);
		foreach (Entities::convertEntities($this) as $en) 		{
			$sum = $sum->add($en->GetValDecimalByKey($key));
		}
		return $sum;
	}
	public function GetSumDecimalByKey_String_String_Object ($key, $attrOfGroup, $valOfGroup) // [String key, String attrOfGroup, Object valOfGroup]
	{
		$sum = new BigDecimal(0);
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($valOfGroup->equals($en->GetValStrByKey($attrOfGroup)))
			{
				$sum = $sum->add($en->GetValDecimalByKey($key));
			}
		}
		return $sum;
	}
	public function GetAvgDecimalByKey ($key) // [String key]
	{
		if (($this->size() == 0))
		{
			return $BigDecimal->ZERO;
		}
		$sum = new BigDecimal(0);
		foreach (Entities::convertEntities($this) as $en) 		{
			$sum = $sum->add($en->GetValDecimalByKey($key));
		}
		return $sum->divide(new BigDecimal($this->size()));
	}
	public function GetAvgIntByKey ($key) // [String key]
	{
		if (($this->size() == 0))
		{
			return $BigDecimal->ZERO;
		}
		$sum = new BigDecimal(0);
		foreach (Entities::convertEntities($this) as $en) 		{
			$sum = $sum->add($en->GetValDecimalByKey($key));
		}
		return $sum->divide(new BigDecimal($this->size()));
	}
	public function GetSumIntByKey ($key) // [String key]
	{
		$sum = 0;
		foreach (Entities::convertEntities($this) as $en) 		{
			$sum += $en->GetValIntByKey($key);
		}
		return $sum;
	}
	public function GetSumFloatByKey ($key) // [String key]
	{
		$sum = 0;
		foreach (Entities::convertEntities($this) as $en) 		{
			$sum += $en->GetValFloatByKey($key);
		}
		return $sum;
	}
	public function GetSumDoubleByKey ($key) // [String key]
	{
		$sum = doubleval(0);
		foreach (Entities::convertEntities($this) as $en) 		{
			$sum += $en->GetValDoubleByKey($key);
		}
		return $sum;
	}
	public function GetCountByKey_String_String ($key, $val) // [String key, String val]
	{
		$sum = 0;
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($en->GetValStringByKey($key)->equals($val))
			{
				++$sum;
			}
		}
		return $sum;
	}
	public function GetCountByKey_String_I ($key, $val) // [String key, int val]
	{
		$sum = 0;
		foreach (Entities::convertEntities($this) as $en) 		{
			if (($en->GetValIntByKey($key) == $val))
			{
				++$sum;
			}
		}
		return $sum;
	}
	public function FlodInCash () 
	{
		$qo = QueryObject::constructor__Entities($this);
		$num = $qo->DoQuery();
		$en = $this->getNewEntity();
		$CashEntity->PubEns($en, $this, $en->getPK());
		Log->DefaultLogWriteLineInfo((((("成功[" . $en) . "-") . $num) . "]放入缓存�?"));
		return $num;
	}
	public function RemoveEn_Entity ($entity) // [Entity entity]
	{
		$this->remove($entity);
	}
	public function RemoveEn_String ($pk) // [String pk]
	{
		$key = $this->getNewEntity()->getPK();
			/* match: String_String */
		$this->RemoveEn_String_String($key, $pk);
	}
	public function RemoveEn_String_String ($key, $val) // [String key, String val]
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($en->GetValStringByKey($key)->equals($val))
			{
				$this->RemoveEn_Entity($en);
				return ;
			}
		}
	}
	public function remove ($pks) // [String pks]
	{
		$mypks = $pks->split("[@]", -1);
		$pkAttr = $this->getNewEntity()->getPK();
		foreach ($mypks as $pk) 		{
			if ((($pk == NULL) || ($pk->length() == 0)))
			{
				continue;
			}
			/* match: String_String */
			$this->RemoveEn_String_String($pkAttr, $pk);
		}
	}
	public function ClearTable () 
	{
		$en = $this->getNewEntity();
		return $en->RunSQL_String(("DELETE FROM " . $en->getEnMap()->getPhysicsTable()));
	}
	public function Delete () 
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			if (($en)->getIsExits())
			{
				($en)->Delete();
			}
		}
		$this->clear();
	}
	public function RunSQL ($sql) // [String sql]
	{
		return $this->getNewEntity()->RunSQL_String($sql);
	}
	public function Delete_String_Object ($key, $val) // [String key, Object val]
	{
		$en = $this->getNewEntity();
		$ps = new Paras();
		$ps->SQL = (((((("DELETE FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $key) . "=") . $en->getHisDBVarStr()) . "p");
		if (($val->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p", $val);
			}
			else
			{
				$ps->Add("p", $val);
			}
		}
		else
		{
			$ps->Add("p", $val);
		}
		$ps->Add("p", $val);
		return $en->RunSQL_Paras($ps);
	}
	public function Delete_String_Object_String_Object ($key1, $val1, $key2, $val2) // [String key1, Object val1, String key2, Object val2]
	{
		$en = $this->getNewEntity();
		$ps = new Paras();
		$ps->SQL = (((((((((("DELETE FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $key1) . "=") . $en->getHisDBVarStr()) . "p1 AND ") . $key2) . "=") . $en->getHisDBVarStr()) . "p2");
		if (($val1->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key1);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p1", $val1);
			}
			else
			{
				$ps->Add("p1", $val1);
			}
		}
		else
		{
			$ps->Add("p1", $val1);
		}
		if (($val2->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key2);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p2", $val2);
			}
			else
			{
				$ps->Add("p2", $val2);
			}
		}
		else
		{
			$ps->Add("p2", $val2);
		}
		return $en->RunSQL_Paras($ps);
	}
	public function Delete_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3) // [String key1, Object val1, String key2, Object val2, String key3, Object val3]
	{
		$en = $this->getNewEntity();
		$ps = new Paras();
		$ps->SQL = (((((((((((((("DELETE FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $key1) . "=") . $en->getHisDBVarStr()) . "p1 AND ") . $key2) . "=") . $en->getHisDBVarStr()) . "p2 AND ") . $key3) . "=") . $en->getHisDBVarStr()) . "p3");
		if (($val1->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key1);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p1", $val1);
			}
			else
			{
				$ps->Add("p1", $val1);
			}
		}
		else
		{
			$ps->Add("p1", $val1);
		}
		if (($val2->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key2);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p2", $val2);
			}
			else
			{
				$ps->Add("p2", $val2);
			}
		}
		else
		{
			$ps->Add("p2", $val2);
		}
		if (($val3->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key3);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p3", $val3);
			}
			else
			{
				$ps->Add("p3", $val3);
			}
		}
		else
		{
			$ps->Add("p3", $val3);
		}
		return $en->RunSQL_Paras($ps);
	}
	public function Delete_String_Object_String_Object_String_Object_String_Object ($key1, $val1, $key2, $val2, $key3, $val3, $key4, $val4) // [String key1, Object val1, String key2, Object val2, String key3, Object val3, String key4, Object val4]
	{
		$en = $this->getNewEntity();
		$ps = new Paras();
		$ps->SQL = (((((((((((((((((("DELETE FROM " . $en->getEnMap()->getPhysicsTable()) . " WHERE ") . $key1) . "=") . $en->getHisDBVarStr()) . "p1 AND ") . $key2) . "=") . $en->getHisDBVarStr()) . "p2 AND ") . $key3) . "=") . $en->getHisDBVarStr()) . "p3 AND ") . $key4) . "=") . $en->getHisDBVarStr()) . "p4");
		if (($val1->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key1);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p1", $val1);
			}
			else
			{
				$ps->Add("p1", $val1);
			}
		}
		else
		{
			$ps->Add("p1", $val1);
		}
		if (($val2->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key2);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p2", $val2);
			}
			else
			{
				$ps->Add("p2", $val2);
			}
		}
		else
		{
			$ps->Add("p2", $val2);
		}
		if (($val3->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key3);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p3", $val3);
			}
			else
			{
				$ps->Add("p3", $val3);
			}
		}
		else
		{
			$ps->Add("p3", $val3);
		}
		if (($val4->getClass() . String))
		{
			$attr = $en->getEnMap()->GetAttrByKey($key4);
			if (($attr->getMyDataType() == $DataType->AppString))
			{
				$ps->Add("p4", $val4);
			}
			else
			{
				$ps->Add("p4", $val4);
			}
		}
		else
		{
			$ps->Add("p4", $val4);
		}
		return $en->RunSQL_Paras($ps);
	}
	public function Update () 
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			$en->Update();
		}
	}
	public function Save () 
	{
		foreach (Entities::convertEntities($this) as $en) 		{
			$en->Save();
		}
	}
	public function RetrieveByLike ($key, $vals) // [String key, String vals]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_String_String($key, " LIKE ", $vals);
		return $qo->DoQuery();
	}
	public function Retrieve_String ($pks) // [String pks]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_String_String($this->getNewEntity()->getPK(), " in ", $pks);
		return $qo->DoQuery();
	}
	public function RetrieveInOrderBy ($key, $vals, $orderByKey) // [String key, String vals, String orderByKey]
	{
		$qo = QueryObject::constructor__Entities($this);
		if (($vals->contains("(") ==  FALSE ))
			$qo->AddWhere_String_String_String($key, " IN ", (("(" . $vals) . ")"));
		else
			$qo->AddWhere_String_String_String($key, " IN ", $vals);
		if (($DataType->IsNullOrEmpty($orderByKey) ==  FALSE ))
			/* match: String */
			$qo->addOrderBy_String($orderByKey);
		return $qo->DoQuery();
	}
	public function RetrieveIn ($key, $vals) // [String key, String vals]
	{
		$qo = QueryObject::constructor__Entities($this);
		if (($vals->contains("(") ==  FALSE ))
			$qo->AddWhere_String_String_String($key, " IN ", (("(" . $vals) . ")"));
		else
			$qo->AddWhere_String_String_String($key, " IN ", $vals);
		return $qo->DoQuery();
	}
	public function RetrieveInSQL_String_String ($attr, $sql) // [String attr, String sql]
	{
		$qo = QueryObject::constructor__Entities($this);
			/* match: String_String */
		$qo->AddWhereInSQL_String_String($attr, $sql);
		return $qo->DoQuery();
	}
	public function RetrieveInSQL_String_String_String ($attr, $sql, $orderBy) // [String attr, String sql, String orderBy]
	{
		$qo = QueryObject::constructor__Entities($this);
			/* match: String_String */
		$qo->AddWhereInSQL_String_String($attr, $sql);
			/* match: String */
		$qo->addOrderBy_String($orderBy);
		return $qo->DoQuery();
	}
	public function RetrieveInSQL_String ($sql) // [String sql]
	{
		$qo = QueryObject::constructor__Entities($this);
			/* match: String_String */
		$qo->AddWhereInSQL_String_String($this->getNewEntity()->getPK(), $sql);
		return $qo->DoQuery();
	}
	public function RetrieveExistsSQL ($sql) // [String sql]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhereExistsSQL($this->getNewEntity()->getPK(), $sql);
		return $qo->DoQuery();
	}
	public function RetrieveInSQL_Order ($sql, $orderby) // [String sql, String orderby]
	{
		$qo = QueryObject::constructor__Entities($this);
			/* match: String_String */
		$qo->AddWhereInSQL_String_String($this->getNewEntity()->getPK(), $sql);
			/* match: String */
		$qo->addOrderBy_String($orderby);
		return $qo->DoQuery();
	}
	public function Retrieve_String_b ($key, $val) // [String key, boolean val]
	{
		$qo = QueryObject::constructor__Entities($this);
		if ($val)
		{
			$qo->AddWhere_String_I($key, 1);
		}
		else
		{
			$qo->AddWhere_String_I($key, 0);
		}
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object ($key, $val) // [String key, Object val]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String ($key, $val, $orderby) // [String key, Object val, String orderby]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
			/* match: String */
		$qo->addOrderBy_String($orderby);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object ($key, $val, $key2, $val2) // [String key, Object val, String key2, Object val2]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String ($key, $val, $key2, $val2, $ordery) // [String key, Object val, String key2, Object val2, String ordery]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
			/* match: String */
		$qo->addOrderBy_String($ordery);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String_Object ($key, $val, $key2, $val2, $key3, $val3) // [String key, Object val, String key2, Object val2, String key3, Object val3]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key3, $val3);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String_Object_String ($key, $val, $key2, $val2, $key3, $val3, $ordery) // [String key, Object val, String key2, Object val2, String key3, Object val3, String ordery]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key3, $val3);
			/* match: String */
		$qo->addOrderBy_String($ordery);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String_Object_String_Object ($key, $val, $key2, $val2, $key3, $val3, $key4, $val4) // [String key, Object val, String key2, Object val2, String key3, Object val3, String key4, Object val4]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key3, $val3);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key4, $val4);
		return $qo->DoQuery();
	}
	public function Retrieve_String_Object_String_Object_String_Object_String_Object_String ($key, $val, $key2, $val2, $key3, $val3, $key4, $val4, $orderBy) // [String key, Object val, String key2, Object val2, String key3, Object val3, String key4, Object val4, String orderBy]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->AddWhere_String_Object($key, $val);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key2, $val2);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key3, $val3);
		$qo->addAnd();
		$qo->AddWhere_String_Object($key4, $val4);
			/* match: String */
		$qo->addOrderBy_String($orderBy);
		return $qo->DoQuery();
	}
	public function RetrieveAll () 
	{
		return $this->RetrieveAll_I(NULL);
	}
	public function RetrieveAllOrderByRandom () 
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->addOrderByRandom();
		return $qo->DoQuery();
	}
	public function RetrieveAllOrderByRandom_I ($topNum) // [int topNum]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->setTop($topNum);
		$qo->addOrderByRandom();
		return $qo->DoQuery();
	}
	public function RetrieveAll_I_String ($topNum, $orderby) // [int topNum, String orderby]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->setTop($topNum);
			/* match: String */
		$qo->addOrderBy_String($orderby);
		return $qo->DoQuery();
	}
	public function RetrieveAll_I_String_b ($topNum, $orderby, $isDesc) // [int topNum, String orderby, boolean isDesc]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->setTop($topNum);
		if ($isDesc)
		{
			/* match: String */
			$qo->addOrderByDesc_String($orderby);
		}
		else
		{
			/* match: String */
			$qo->addOrderBy_String($orderby);
		}
		return $qo->DoQuery();
	}
	public function RetrieveAll_String ($orderBy) // [String orderBy]
	{
		$qo = QueryObject::constructor__Entities($this);
		if (($orderBy . NULL))
		{
			/* match: String */
			$qo->addOrderBy_String($orderBy);
		}
		return $qo->DoQuery();
	}
	public function RetrieveAll_String_String ($orderBy1, $orderBy2) // [String orderBy1, String orderBy2]
	{
		$qo = QueryObject::constructor__Entities($this);
		if (($orderBy1 . NULL))
		{
			/* match: String_String */
			$qo->addOrderBy_String_String($orderBy1, $orderBy2);
		}
		return $qo->DoQuery();
	}
	public function RetrieveAll_I ($MaxNum) // [int MaxNum]
	{
		$qo = QueryObject::constructor__Entities($this);
		$qo->setTop($MaxNum);
		return $qo->DoQuery();
	}
	public function RetrieveAllToTable () 
	{
		$qo = QueryObject::constructor__Entities($this);
		return $qo->DoQueryToTable();
	}
	protected function DealBoolTypeInDataTable ($en, $dt) // [Entity en, DataTable dt]
	{
		throw new \RuntimeException("编译不�?�过");
	}
	public function ToDataTableField () 
	{
			/* match: String */
		return $this->ToDataTableField_String("dt");
	}
	public function ToDataTableStringField () 
	{
			/* match: String */
		return $this->ToDataTableStringField_String("dt");
	}
	public function ToDataTableStringField_String ($tableName) // [String tableName]
	{
		$dt = $this->ToEmptyTableStringField();
		$en = $this->getNewEntity();
		$dt->TableName = $tableName;
		foreach (Entities::convertEntities($this) as $myen) 		{
			$dr = $dt->NewRow();
			foreach ($en->getEnMap()->getAttrs() as $attr) 			{
				if (($attr->getMyDataType() == $DataType->AppBoolean))
				{
					if (($myen->GetValIntByKey($attr->getKey()) == 1))
					{
						$dr->setValue($attr->getKey(), "1");
					}
					else
					{
						$dr->setValue($attr->getKey(), "0");
					}
					continue;
				}
				if ((($attr->getMyFieldType() == FieldType::$FK) || ($attr->getMyFieldType() == FieldType::$PKFK)))
				{
					$dr->setValue($attr->getKey(), $myen->GetValByKey($attr->getKey())->trim());
				}
				else
				{
					$dr->setValue($attr->getKey(), $myen->GetValByKey($attr->getKey()));
				}
			}
			$dt->Rows->add($dr);
		}
		return $dt;
	}
	public function ToDataTableField_String ($tableName) // [String tableName]
	{
		$dt = $this->ToEmptyTableField();
		$en = $this->getNewEntity();
		$attrs = $en->getEnMap()->getAttrs();
		$dt->TableName = $tableName;
		foreach (Entities::convertEntities($this) as $myen) 		{
			$dr = $dt->NewRow();
			foreach ($attrs as $attr) 			{
				if (($attr->getMyDataType() == $DataType->AppBoolean))
				{
					if (($myen->GetValIntByKey($attr->getKey()) == 1))
					{
						$dr->setValue($attr->getKey(), "1");
					}
					else
					{
						$dr->setValue($attr->getKey(), "0");
					}
					continue;
				}
				if (($attr->getMyFieldType()->equals(FieldType::$FK) || $attr->getMyFieldType()->equals(FieldType::$PKFK)))
				{
					$dr->setValue($attr->getKey(), $myen->GetValByKey($attr->getKey())->trim());
				}
				else
				{
					$dr->setValue($attr->getKey(), $myen->GetValByKey($attr->getKey()));
				}
			}
			$dt->Rows->add($dr);
		}
		return $dt;
	}
	public function ToDataTableDesc () 
	{
		$dt = $this->ToEmptyTableDesc();
		$en = $this->getNewEntity();
		$dt->TableName = $en->getEnMap()->getPhysicsTable();
		foreach (Entities::convertEntities($this) as $myen) 		{
			$dr = $dt->NewRow();
			foreach ($en->getEnMap()->getAttrs() as $attr) 			{
				if (($attr->getMyDataType() == $DataType->AppBoolean))
				{
					if ($myen->GetValBooleanByKey($attr->getKey()))
					{
						$dr->setValue($attr->getDesc(), "�?");
					}
					else
					{
						$dr->setValue($attr->getDesc(), "�?");
					}
					continue;
				}
				$dr->setValue($attr->getDesc(), $myen->GetValByKey($attr->getKey()));
			}
			$dt->Rows->add($dr);
		}
		return $dt;
	}
	public function ToEmptyTableDescField () 
	{
		$dt = new DataTable();
		$en = $this->getNewEntity();
		try 
		{
			foreach ($en->getEnMap()->getAttrs() as $attr) 			{
				switch ($attr->getMyDataType()) {
					case $DataType->AppString:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), String));
						break;
					case $DataType->AppInt:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), Integer));
						break;
					case $DataType->AppFloat:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), Float));
						break;
					case $DataType->AppBoolean:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), String));
						break;
					case $DataType->AppDouble:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), Double));
						break;
					case $DataType->AppMoney:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), Double));
						break;
					case $DataType->AppDate:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), String));
						break;
					case $DataType->AppDateTime:
						$dt->Columns->Add(new DataColumn(($attr->getDesc()->trim() + $attr->getKey()), String));
						break;
					default:
						throw new \RuntimeException("@bulider insert sql error: 没有这个数据类型");
				}
			}
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException((($en->getEnDesc() . " error ") . $ex->getMessage()));
		}
		return $dt;
	}
	public function ToDataTableDescField () 
	{
		$dt = $this->ToEmptyTableDescField();
		$en = $this->getNewEntity();
		$dt->TableName = $en->getEnMap()->getPhysicsTable();
		foreach (Entities::convertEntities($this) as $myen) 		{
			$dr = $dt->NewRow();
			foreach ($en->getEnMap()->getAttrs() as $attr) 			{
				if (($attr->getMyDataType() == $DataType->AppBoolean))
				{
					if ($myen->GetValBooleanByKey($attr->getKey()))
					{
						$dr->setValue(($attr->getDesc()->trim() + $attr->getKey()), "�?");
					}
					else
					{
						$dr->setValue(($attr->getDesc()->trim() + $attr->getKey()), "�?");
					}
					continue;
				}
				$dr->setValue(($attr->getDesc()->trim() + $attr->getKey()), $myen->GetValByKey($attr->getKey()));
			}
			$dt->Rows->add($dr);
		}
		return $dt;
	}
	public function ToStringOfPK ($flag, $isCutEndFlag) // [String flag, boolean isCutEndFlag]
	{
		$pk = NULL;
		foreach (Entities::convertEntities($this) as $en) 		{
			$pk += ($en->getPKVal() . $flag);
		}
		if ($isCutEndFlag)
		{
			$pk = $pk->substring(0, ($pk->length() - 1));
		}
		return $pk;
	}
	public function ToStringOfSQLModelByPK () 
	{
		if (($this->size() == 0))
		{
			return "''";
		}
		return $this->ToStringOfSQLModelByKey($this->getItem(0)->getPK());
	}
	public function ToStringOfSQLModelByKey ($key) // [String key]
	{
		if (($this->size() == 0))
		{
			return "''";
		}
		$pk = NULL;
		foreach (Entities::convertEntities($this) as $en) 		{
			$pk += (("'" . $en->GetValStringByKey($key)) . "',");
		}
		$pk = $pk->substring(0, ($pk->length() - 1));
		return $pk;
	}
	public function ToEmptyTableField_old () 
	{
		$dt = new DataTable();
		$en = $this->getNewEntity();
		$dt->TableName = $en->getEnMap()->getPhysicsTable();
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String));
					break;
				case $DataType->AppInt:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Integer));
					break;
				case $DataType->AppFloat:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Float));
					break;
				case $DataType->AppBoolean:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String));
					break;
				case $DataType->AppDouble:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Double));
					break;
				case $DataType->AppMoney:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Double));
					break;
				case $DataType->AppDate:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String));
					break;
				case $DataType->AppDateTime:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String));
					break;
				default:
					throw new \RuntimeException("@bulider insert sql error: 没有这个数据类型");
			}
		}
		return $dt;
	}
	public function ToEmptyTableField () 
	{
		$dt = new DataTable();
		$en = $this->getNewEntity();
		$dt->TableName = $en->getEnMap()->getPhysicsTable();
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			switch ($attr->getMyDataType()) {
				case $DataType->AppString:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				case $DataType->AppInt:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Integer,  TRUE ));
					break;
				case $DataType->AppFloat:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Float,  TRUE ));
					break;
				case $DataType->AppBoolean:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				case $DataType->AppDouble:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Double,  TRUE ));
					break;
				case $DataType->AppMoney:
					$dt->Columns->Add(new DataColumn($attr->getKey(), Double,  TRUE ));
					break;
				case $DataType->AppDate:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				case $DataType->AppDateTime:
					$dt->Columns->Add(new DataColumn($attr->getKey(), String,  TRUE ));
					break;
				default:
					throw new \RuntimeException("@bulider insert sql error: 没有这个数据类型");
			}
		}
		return $dt;
	}
	public function ToEmptyTableStringField () 
	{
		$dt = new DataTable();
		$en = $this->getNewEntity();
		$dt->TableName = $en->getEnMap()->getPhysicsTable();
		foreach ($en->getEnMap()->getAttrs() as $attr) 		{
			$dt->Columns->Add(new DataColumn($attr->getKey(), String));
		}
		return $dt;
	}
	public function ToEmptyTableDesc () 
	{
		$dt = new DataTable();
		$en = $this->getNewEntity();
		try 
		{
			foreach ($en->getEnMap()->getAttrs() as $attr) 			{
				switch ($attr->getMyDataType()) {
					case $DataType->AppString:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), String));
						break;
					case $DataType->AppInt:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), Integer));
						break;
					case $DataType->AppFloat:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), Float));
						break;
					case $DataType->AppBoolean:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), String));
						break;
					case $DataType->AppDouble:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), Double));
						break;
					case $DataType->AppMoney:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), Double));
						break;
					case $DataType->AppDate:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), String));
						break;
					case $DataType->AppDateTime:
						$dt->Columns->Add(new DataColumn($attr->getDesc(), String));
						break;
					default:
						throw new \RuntimeException("@bulider insert sql error: 没有这个数据类型");
				}
			}
		}
		catch (\RuntimeException $ex)
		{
			throw new \RuntimeException((($en->getEnDesc() . " error ") . $ex->getMessage()));
		}
		return $dt;
	}
	public function RetrieveFromCashInSQL ($cashKey, $inSQL) // [String cashKey, String inSQL]
	{
		$this->clear();
		$tempVar = $Cash->GetEnsDataExt($cashKey);
		$ens = (( (($tempVar instanceof Entities)) ? $tempVar : NULL ));
		if (($ens == NULL))
		{
			$qo = QueryObject::constructor__Entities($this);
			/* match: String_String */
			$qo->AddWhereInSQL_String_String($this->getNewEntity()->getPK(), $inSQL);
			$qo->DoQuery();
			$Cash->SetEnsDataExt($cashKey, $this);
		}
		else
		{
			$this->AddEntities_Entities($ens);
		}
		return $this->size();
	}
	public function RetrieveFromCash_String_Object_I_String_b ($attrKey, $val, $top, $orderBy, $isDesc) // [String attrKey, Object val, int top, String orderBy, boolean isDesc]
	{
		$cashKey = ((((($this . $attrKey) . $val) . $top) . $orderBy) . $isDesc);
		$this->clear();
		$ens = $Cash->GetEnsDataExt($cashKey);
		if (($ens == NULL))
		{
			$qo = QueryObject::constructor__Entities($this);
			$qo->setTop($top);
			if (($attrKey->equals("") . ($attrKey . NULL)))
			else
			{
				$qo->AddWhere_String_Object($attrKey, $val);
			}
			if (($orderBy . NULL))
			{
				if ($isDesc)
				{
			/* match: String */
					$qo->addOrderByDesc_String($orderBy);
				}
				else
				{
			/* match: String */
					$qo->addOrderBy_String($orderBy);
				}
			}
			$qo->DoQuery();
			$Cash->SetEnsDataExt($cashKey, $this);
		}
		else
		{
			$this->AddEntities_Entities($ens);
		}
		return $this->size();
	}
	public function RetrieveFromCash_String_Object ($attrKey, $val) // [String attrKey, Object val]
	{
			/* match: String_Object_I_String_b */
		return $this->RetrieveFromCash_String_Object_I_String_b($attrKey, $val, 99999, NULL,  TRUE );
	}
	public function RetrieveFromCash_String_Object_String ($attrKey, $val, $orderby) // [String attrKey, Object val, String orderby]
	{
			/* match: String_Object_I_String_b */
		return $this->RetrieveFromCash_String_Object_I_String_b($attrKey, $val, 99999, $orderby,  TRUE );
	}
	public function RetrieveFromCash_String_b_I ($orderBy, $isDesc, $top) // [String orderBy, boolean isDesc, int top]
	{
			/* match: String_Object_I_String_b */
		return $this->RetrieveFromCash_String_Object_I_String_b(NULL, NULL, $top, $orderBy, $isDesc);
	}
	public function ContainsAnyOnePK ($keys) // [String keys]
	{
		$keys = (("," . $keys) . ",");
		foreach (Entities::convertEntities($this) as $en) 		{
			if ($keys->contains((("," . $en->getPKVal()) . ",")))
			{
				return  TRUE ;
			}
		}
		return  FALSE ;
	}
	public function ContainsAllPK ($keys) // [String keys]
	{
		$keys = (("," . $keys) . ",");
		foreach (Entities::convertEntities($this) as $en) 		{
			if (!$keys->contains((("," . $en->getPKVal()) . ",")))
			{
				return  FALSE ;
			}
		}
		return  TRUE ;
	}
	public function toString () 
	{
		return $this->getClass()->getName();
	}
	public function toList () 
	{
		return $this;
	}
	public function ToJavaListEn () 
	{
		return $this;
	}
	public function ToJson () 
	{
			/* match: String */
		return $this->ToJson_String("dt");
	}
	public function ToJson_String ($dtName) // [String dtName]
	{
			/* match: String */
		return $BP->Tools->Json->ToJson($this->ToDataTableField_String($dtName));
	}
}
Entities::__staticinit(); // initialize static vars for this class on load
?>
